<template>
	<div class="system-dic-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column prop="crontab_id" label="任务ID" show-overflow-tooltip></el-table-column>
				<el-table-column prop="target" label="调用目标" show-overflow-tooltip></el-table-column>
                <el-table-column label="调用参数" show-overflow-tooltip>
                    <template #default="scope">
                        {{ scope.row.parameter || '-' }}
                    </template>
                </el-table-column>
                <el-table-column prop="exception" label="异常信息输出" show-overflow-tooltip></el-table-column>
				<el-table-column prop="status" label="状态">
					<template #default="scope">
						<el-tag type="success" v-if="scope.row.return_code == 0">成功</el-tag>
						<el-tag type="danger" v-else>失败</el-tag>
					</template>
				</el-table-column>
                <el-table-column label="执行时间" show-overflow-tooltip>
                    <template #default="scope">
						{{ dateFormatYMDHMS( scope.row.running_time * 1000 ) }}
					</template>
                </el-table-column>
                <el-table-column label="创建时间" show-overflow-tooltip>
                    <template #default="scope">
						{{ dateFormatYMDHMS(scope.row.create_time * 1000 ) }}
					</template>
                </el-table-column>
                <el-table-column label="更新时间" show-overflow-tooltip>
                    <template #default="scope">
						{{ dateFormatYMDHMS(scope.row.update_time * 1000 ) }}
					</template>
                </el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				v-model:current-page="state.tableData.param.page"
				background
				v-model:page-size="state.tableData.param.limit"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</el-card>
	</div>
</template>

<script setup name="crontabFlow">
import { reactive, onMounted } from 'vue';
import { systemCrontabApi } from '/@/api/system/crontab/index';
import commonFunction from '/@/utils/commonFunction';
// 定义变量内容
const { dateFormatYMDHMS } = commonFunction();
const state = reactive({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			page: 1,
			limit: 10,
		},
	},
});

// 初始化表格数据
const getTableData = () => {
	state.tableData.loading = true;
	systemCrontabApi().flow(state.tableData.param).then(res=>{
		state.tableData.data = res.data.list;
        state.tableData.total = res.data.total;
        state.tableData.loading = false;
	})
};
// 分页改变
const onHandleSizeChange = (val) => {
	state.tableData.param.limit = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val) => {
	state.tableData.param.page = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>
